package nl.mayisal.sql;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;

public class SQLResultSet {
	private final Statement statement;
	private final ResultSet resultSet;
	private boolean isOpen = false;

	public SQLResultSet(Statement statement, ResultSet resultSet) {
		this.statement = statement;
		this.resultSet = resultSet;
		this.isOpen = true;
	}

	public void close() {
		try {
			this.resultSet.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		try {
			this.statement.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	@Override
	protected void finalize() throws Throwable {
		super.finalize();
		if (this.isOpen)
			this.close();
	}

	public int getInt(int column) throws SQLException {
		return this.resultSet.getInt(column);
	}

	public ResultSetMetaData getMetaData() throws SQLException {
		return this.resultSet.getMetaData();
	}

	public boolean next() throws SQLException {
		return this.resultSet.next();
	}
}
